import requests
import lxml.etree as le
import pandas as pd
#使用xpath获取目录
url = 'https://www.runoob.com/html/html-tutorial.html'
x = '//div[@id="leftcolumn"]/a/text()'
content = requests.get(url).content
contentx = le.HTML(content)
rets = contentx.xpath(x)
for ret in rets:
   print(ret.strip())

#写入数据
df_fold=pd.DataFrame(
 columns ={'level1','level2'}
)
level1s=[]
level2s=[]
for yiji,erji in rets:
    level1s.append(yiji)
    level2s.append(erji)
df_fold['level1']=level1s
df_fold['level2']=level2s
writer = pd.ExcelWriter('category.xlsx')
df_fold.to_excel(writer,sheet_name='职位类别')
writer.save()




